#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDebug>
#include <vector>
#include <memory>
#include "Stock.h"

using namespace std;

vector<shared_ptr<Stock>> getStocks()
{

}

bool saveStock(const shared_ptr<Stock>& stock)
{

}

int addStockInfo()
{
	vector<shared_ptr<Stock>> stocks = getStocks();
	QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
	db.setDatabaseName("stock.db");
	if (!db.open())
	{
		qDebug() << "open database failed.";
		return 1;
	}

	QString sql = "create table if exists stocklist(id char(16) primary key, name nchar(4), code char(6) not null, pinyin char(4));";
	QSqlQuery query;
	query.prepare(sql);
	if (!query.exec())
	{
		qDebug() << "create table failed.";
		return 2;
	}

	foreach(shared_ptr<Stock> stock, stocks)
	{
		if (saveStock(stock))
			qDebug() << "insert value " << stock->pinyin() << " failed.";
	}
	return 0;
}

int main(int argc, char** argv)
{
	QCoreApplication a(argc, argv);
	return addStockInfo();
}
